unit uAppConfig;

interface

uses
  SysUtils, ActiveX, uDZPersistent;

type
  TAppConfig = class(TDzPersistent)
  private
    fListenPort: Word;
    fSmsAccountName: string;
    fSmsPassword: string;
    fWorkThreadCount: Integer;
  public
    constructor Create; override;
    destructor Destroy; override;
  published
    property ListenPort: Word read fListenPort write fListenPort;
    property WorkThreadCount: Integer read fWorkThreadCount write fWorkThreadCount;
    property SmsAccountName: string read fSmsAccountName write fSmsAccountName;
    property SmsPassword: string read fSmsPassword write fSmsPassword;
  end;

function AppConfig: TAppConfig;

implementation

var
  AppConfig: TAppConfig;

function AppConfig: TAppConfig;
begin
  Result := AppConfig;
end;

{ TAppConfig }

constructor TAppConfig.Create;
var
  ConfigFileName: string;
begin
  inherited;
  ConfigFileName := ExtractFilePath(ParamStr(0)) + 'settings.conf';
  if FileExists(ConfigFileName) then LoadFromFile(ConfigFileName, afXML);
  if fListenPort = 0 then fListenPort := 8080;
end;

destructor TAppConfig.Destroy;
begin
  SaveToFile(ExtractFilePath(ParamStr(0)) + 'settings.conf', afXML);
  inherited;
end;

initialization
  CoInitialize(nil);
  AppConfig := TAppConfig.Create;

finalization
  AppConfig.Free;
  CoUninitialize;

end.
